/*
 * mainWin.java
 *
 * Created on January 21, 2008, 8:42 PM
 */


import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.table.*;
import java.io.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.ArrayList;
/**
 *
 * @author  Owner
 */

public class mainWin extends javax.swing.JFrame {
    /** Creates new form mainWin */
    private int x, y;
    private background[] bkData;
    private background[][] bkImage;
    
    private Sprite[] SprtData;
    private Sprite[][] SprtImage;
    private People[] PplData;
    private People[][] PplImage;
    private int numOn = 0;
    private Writer output;
    private BufferedReader input;
    private File tempFile;

    public mainWin(int Ix, int Iy) {
        x=Ix;
        y=Iy;
        bkImage = new background[x][y];
         bkData = new background[1];
         bkData[0] = new background(new ImageIcon("trans.png"), "<None>", false);
         
         SprtImage = new Sprite[x][y];
         SprtData = new Sprite[1];
         SprtData[0] = new Sprite(new ImageIcon("trans.png"), "<None>");
         
         PplImage = new People[x][y];
         PplData = new People[1];
         PplData[0] = new People(new ImageIcon("trans.png"), "<None>");
         
         for(int r=0;r<bkImage[0].length;r++)
             for(int c=0;c<bkImage.length;c++)
                 bkImage[r][c] = bkData[0];
         
         for(int r = 0; r < SprtImage[0].length; r++)
               for(int c = 0; c < SprtImage.length; c++)
                   SprtImage[r][c] = SprtData[0];
         
         for(int r = 0; r < PplImage[0].length; r++)
             for(int c = 0; c < PplImage.length; c++)
                 PplImage[r][c] = PplData[0];
try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(Exception e) {
      System.out.println("Error setting native LAF: " + e);
    }

        initComponents();
        for (int i=0; i<jTable1.getColumnCount(); i++) {
                    TableColumn column = jTable1.getColumnModel().getColumn(i);
                    column.setPreferredWidth(50);
                    column.setMinWidth(50);
                    column.setMaxWidth(50);
                }
        

        
        //jTable1.setRowHeight(50);
      //  jTable1.setShowGrid(false);
           
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane7 = new javax.swing.JScrollPane();
        jList6 = new javax.swing.JList();
        jButton31 = new javax.swing.JButton();
        jButton32 = new javax.swing.JButton();
        jButton33 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane8 = new javax.swing.JScrollPane();
        jList7 = new javax.swing.JList();
        jButton22 = new javax.swing.JButton();
        jButton23 = new javax.swing.JButton();
        jButton24 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jList4 = new JList(bkData);
        backEdit = new javax.swing.JButton();
        backRem = new javax.swing.JButton();
        backAdd = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jList5 = new JList(SprtData);
        jButton28 = new javax.swing.JButton();
        jButton29 = new javax.swing.JButton();
        jButton30 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane9 = new javax.swing.JScrollPane();
        jList8 = new javax.swing.JList();
        jButton34 = new javax.swing.JButton();
        jButton35 = new javax.swing.JButton();
        jButton36 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane10 = new javax.swing.JScrollPane();
        jList9 = new javax.swing.JList();
        jButton37 = new javax.swing.JButton();
        jButton38 = new javax.swing.JButton();
        jButton39 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        Object[][] data = new Object [x][y];
        for(int r=0;r<data.length;r++)
        for(int c=0;c<data[0].length;c++)
        data[r][c]=new ThreeImage(new ImageIcon("trans.png"), new ImageIcon("trans.png"),new ImageIcon("trans.png"));
        String[] top = new String[x];
        jTable1 = new JTable()
        {
            //  Returning the Class of each column will allow different
            //  renderers to be used based on Class
            public Class getColumnClass(int column)
            {
                return ThreeImage.class;
            }
        };
        jTable1.setDefaultRenderer(ThreeImage.class, new triImageRenderer());

        ;
        jLabel7 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new JList(bkData);
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Untitled - Cenex Map Creator Alpha");
        setBounds(new java.awt.Rectangle(500, 200, 0, 0));
        setForeground(java.awt.Color.white);
        setResizable(false);

        jLabel1.setText("Player Name:");

        jTextField1.setToolTipText("Leave blank for choice");
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Player Health:");

        jTextField2.setText("100");
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jLabel3.setText("/");

        jLabel4.setText("Player Armor:");

        jTextField3.setText("100");

        jTextField4.setText("0");
        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        jLabel5.setText("/");

        jTextField5.setText("0");

        jButton4.setText("Set");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton4MouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Main Player", jPanel1);

        jScrollPane7.setViewportView(jList6);

        jButton31.setText("Edit");

        jButton32.setText("Remove");

        jButton33.setText("Add");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton31, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                    .addComponent(jButton32, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton33, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                .addGap(214, 214, 214))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton33)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton31, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton32))
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Guns", jPanel2);

        jScrollPane8.setViewportView(jList7);

        jButton22.setText("Edit");

        jButton23.setText("Remove");

        jButton24.setText("Add");
        jButton24.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton24ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton22, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                    .addComponent(jButton23, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton24, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                .addGap(214, 214, 214))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButton24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton22, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton23))
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Items", jPanel3);

        jList4.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane5.setViewportView(jList4);

        backEdit.setText("Edit");
        backEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backEditActionPerformed(evt);
            }
        });

        backRem.setText("Remove");
        backRem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backRemActionPerformed(evt);
            }
        });

        backAdd.setText("Add");
        backAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backAddActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(backEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                    .addComponent(backRem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(backAdd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                .addGap(214, 214, 214))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(backAdd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(backEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(backRem)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Background", jPanel4);

        jScrollPane6.setViewportView(jList5);

        jButton28.setText("Edit");
        jButton28.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton28MouseReleased(evt);
            }
        });

        jButton29.setText("Remove");
        jButton29.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton29MouseReleased(evt);
            }
        });
        jButton29.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton29ActionPerformed(evt);
            }
        });

        jButton30.setText("Add");
        jButton30.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton30ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton28, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                    .addComponent(jButton29, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton30, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                .addGap(214, 214, 214))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jButton30)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton28, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton29))
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Sprites", jPanel5);

        jScrollPane9.setViewportView(jList8);

        jButton34.setText("Edit");

        jButton35.setText("Remove");

        jButton36.setText("Add");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton34, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                    .addComponent(jButton35, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton36, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                .addGap(214, 214, 214))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jButton36)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton34, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton35))
                    .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Enemy", jPanel6);

        jScrollPane10.setViewportView(jList9);

        jButton37.setText("Edit");

        jButton38.setText("Remove");

        jButton39.setText("Add");
        jButton39.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton39ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton37, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                    .addComponent(jButton38, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton39, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                .addGap(214, 214, 214))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jButton39)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton37, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton38))
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("NPC", jPanel7);

        jTable1.setModel(new javax.swing.table.DefaultTableModel( data , top ));
        jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTable1.setColumnSelectionAllowed(true);
        jTable1.setRowHeight(50);
        jTable1.setRowMargin(0);
        jTable1.setSelectionForeground(new java.awt.Color(51, 0, 255));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                mouseReleasedT1(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);

        jPanel8.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel8.setLayout(new java.awt.CardLayout());

        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jList1MouseReleased(evt);
            }
        });
        jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jList1);

        jPanel8.add(jScrollPane1, "card2");

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Background");
        jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jRadioButton1MouseReleased(evt);
            }
        });
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Sprites");
        jRadioButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jRadioButton2MouseReleased(evt);
            }
        });
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setText("People");
        jRadioButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jRadioButton3MouseReleased(evt);
            }
        });
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jRadioButton1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton3, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton3)
                .addContainerGap(44, Short.MAX_VALUE))
        );

        jLabel6.setText("Background");

        jButton1.setText("Save");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton1MouseReleased(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Open");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("View Tile");
        jButton3.setDefaultCapable(false);
        jButton3.setFocusPainted(false);
        jButton3.setRequestFocusEnabled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addGap(5, 5, 5)
                                .addComponent(jButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 387, Short.MAX_VALUE)
                        .addComponent(jLabel6)
                        .addGap(56, 56, 56))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        // TODO add your handling cdoe here:
        if(jRadioButton1.isSelected()){
            jLabel6.setText("Background");
        }
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void backAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backAddActionPerformed
        // TODO add your handling code here:
        backgroundForm dialog = new backgroundForm(this,true);
        dialog.setVisible(true);
        background currBack = dialog.getBG();
        if(currBack!=null)
        {
            for(int i=0;i<bkData.length;i++)
                // DOES NOT WORK WITH EDIT
               /* if(bkData[i].getName().equals(currBack.getName()))
                {
                     JOptionPane.showMessageDialog(null, "Name already exisits");
                     return;
                }*/
                
            
            currBack.setSym((char)numOn);
            numOn++;
            background[] temp = bkData;
            bkData = new background[temp.length+1];
           for(int i=0;i<temp.length;i++)
            {
                bkData[i] = temp[i];
            }
            bkData[temp.length] = currBack;
            jList4.setListData(bkData);
            if(jRadioButton1.isSelected())
                jList1.setListData(bkData);
        }
        
        
}//GEN-LAST:event_backAddActionPerformed

    private void backEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backEditActionPerformed

        backgroundForm dialog = new backgroundForm(this,true,((background)jList4.getSelectedValue()));
        dialog.setVisible(true);
        background currBack = dialog.getEditedBG();
        if(currBack!=null)
        {
       for(int i=0;i<bkData.length;i++)
       if(bkData[i].getName().equals(currBack.getName()))
       {
          JOptionPane.showMessageDialog(null, "Name already exisits");
          return;
       }
            bkData[jList4.getSelectedIndex()] = currBack;
            
            jList4.setListData(bkData);
            if(jRadioButton1.isSelected())
                jList1.setListData(bkData);
        }
}//GEN-LAST:event_backEditActionPerformed

    private void backRemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backRemActionPerformed
      if(bkData.length>0&&jList4.getSelectedIndex()!=0)
      {
        background[] temp = bkData;
        bkData = new background[temp.length-1];
          for(int i=jList4.getSelectedIndex();i<temp.length-1;i++)
                temp[i]=temp[i+1];
         for(int i=0;i<temp.length-1;i++)
         {
             bkData[i] = temp[i];
         }
                   jList4.setListData(bkData);
                  if(jRadioButton1.isSelected())
                    jList1.setListData(bkData);
      }
}//GEN-LAST:event_backRemActionPerformed

    private void listChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listChanged
       // now the list selection has been changed, check the coords on the 
        // array, change the background of the array, 
        // create a new array that contains only imageicons, 
        // and then set the table to that array
        
        
        //first the easy one - 1 thing changed
        // check what one is selected
        if(jList1.getSelectedIndex()!=-1)
        {
        if(jRadioButton1.isSelected()){
            background bgType = bkData[jList1.getSelectedIndex()];
            // one selected. 
            if(jTable1.getSelectedRowCount()>1||jTable1.getSelectedColumnCount()>1)
            {
            
            }
            else
            {
                 bkImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()]=bgType;
                 jTable1.setValueAt(new ThreeImage(((ThreeImage)jTable1.getValueAt(jTable1.getSelectedRow(),jTable1.getSelectedColumn())).img1, 
                         ((ThreeImage)jTable1.getValueAt(jTable1.getSelectedRow(),jTable1.getSelectedColumn())).img2,
                         bgType.getImage().getImage()), 
                 jTable1.getSelectedRow(), jTable1.getSelectedColumn());
            }
        }
        if(jRadioButton2.isSelected()){
            Sprite SprtType = SprtData[jList1.getSelectedIndex()];
            if(jTable1.getSelectedRowCount() > 1 || jTable1.getSelectedColumnCount() > 1)
            {
                
            }
            else
            {
                SprtImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()] = SprtType;
                jTable1.setValueAt(new ThreeImage(
                        ((ThreeImage)jTable1.getValueAt(jTable1.getSelectedRow(),jTable1.getSelectedColumn())).img1,                        
                        SprtType.getImage().getImage(),
                        ((ThreeImage)jTable1.getValueAt(jTable1.getSelectedRow(),jTable1.getSelectedColumn())).img3),
                        jTable1.getSelectedRow(), jTable1.getSelectedColumn());
            }
        }
        if(jRadioButton3.isSelected()){
            People PplType = PplData[jList1.getSelectedIndex()];
            if(jTable1.getSelectedRowCount() > 1 || jTable1.getSelectedColumnCount() > 1){}
            else
            {
                PplImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()] = PplType;
                jTable1.setValueAt(new ThreeImage(
                        PplType.getImage().getImage(),
                        ((ThreeImage)jTable1.getValueAt(jTable1.getSelectedRow(), jTable1.getSelectedColumn())).img2,
                        ((ThreeImage)jTable1.getValueAt(jTable1.getSelectedRow(),jTable1.getSelectedColumn())).img3),
                        jTable1.getSelectedRow(), jTable1.getSelectedColumn());
            }
        }
        
        }
    }//GEN-LAST:event_listChanged

    public void paintTile(int row, int col, background bk, Sprite sp, People pl){
        bkImage[row][col] = bk;
        SprtImage[row][col] = sp;
        PplImage[row][col] = pl;
           background bgType = bk;
            // one selected. 
            if(jTable1.getSelectedRowCount()>1||jTable1.getSelectedColumnCount()>1)
            {
            
            }
            else
            {
                 bkImage[row][col]=bgType;
                 jTable1.setValueAt(new ThreeImage(((ThreeImage)jTable1.getValueAt(row,col)).img1, ((ThreeImage)jTable1.getValueAt(row,col)).img2,bgType.getImage().getImage()), 
                 row, col);
            }
           
            Sprite SprtType = sp;
            if(jTable1.getSelectedRowCount() > 1 || jTable1.getSelectedColumnCount() > 1)
            {
                
            }
            else
            {
                SprtImage[row][col] = SprtType;
                jTable1.setValueAt(new ThreeImage(
                        ((ThreeImage)jTable1.getValueAt(row,col)).img1,                        
                        SprtType.getImage().getImage(),
                        ((ThreeImage)jTable1.getValueAt(row,col)).img3),
                        row, col);
            }
            People PplType = pl;
            if(jTable1.getSelectedRowCount() > 1 || jTable1.getSelectedColumnCount() > 1){}
            else
            {
                PplImage[row][col] = PplType;
                jTable1.setValueAt(new ThreeImage(
                        PplType.getImage().getImage(),
                        ((ThreeImage)jTable1.getValueAt(row, col)).img2,
                        ((ThreeImage)jTable1.getValueAt(row,col)).img3),
                        row, col);
            }

    }
    

    public void setSprtData(Sprite[] sp){
        SprtData = sp;
        jList5.setListData(SprtData);
    }
    public void setBkData(background[] bk){
        bkData = bk;
        jList4.setListData(bkData);
        jList1.setListData(bkData);
    }  
    public void setPplData(People[] pp){
        PplData = pp;
        ArrayList npcs = new ArrayList();
        for(int i = 0; i < PplData.length; i++){
            if(PplData[i].getType().equals("NPC"))
                npcs.add(PplData[i]);       
        }
        People[] npcArray = new People[npcs.size()];
        for(int i = 0; i < npcArray.length; i++)
            npcArray[i] = (People)npcs.get(i);
        jList9.setListData(npcArray);
    }

    private void mouseReleasedT1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseReleasedT1
        
     /*  * if(bkImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()].getWalkOn())
            jCheckBox1.setSelected(true);
        else
            jCheckBox1.setSelected(false);*/
        
        if(jTable1.getSelectedRowCount()>1||jTable1.getSelectedColumnCount()>1)
            jList1.clearSelection();
        else
        {
            if(jRadioButton1.isSelected())
                for(int i=0;i<bkData.length;i++)
                 if(bkImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()].equals(bkData[i]))
                     jList1.setSelectedIndex(i);
            if(jRadioButton2.isSelected())
                for(int i=0;i<SprtData.length;i++)
                 if(SprtImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()].equals(SprtData[i]))
                     jList1.setSelectedIndex(i);
            if(jRadioButton3.isSelected())
                for(int i = 0; i < PplData.length; i++)
                    if(PplImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()].equals(PplData[i]))
                        jList1.setSelectedIndex(i);
        }

        
    }//GEN-LAST:event_mouseReleasedT1

    private void jButton24ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton24ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton24ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
// TODO add your handling code here:
  if(jRadioButton2.isSelected())
      jLabel6.setText("Sprites");
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        // TODO add your handling code here:
if(jRadioButton3.isSelected())
    jLabel6.setText("People");
    }//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jButton30ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton30ActionPerformed
        // TODO add your handling code here:
        
        //Sprite Add
        
        SpriteForm dialog = new SpriteForm(this,true);
        dialog.setVisible(true);
        Sprite currSprt = dialog.getSPRT();
        if(currSprt!=null)
        {
            for(int i=0;i<SprtData.length;i++)
                if(SprtData[i].getName().equals(currSprt.getName()))
                {
                     JOptionPane.showMessageDialog(null, "Name already exisits");
                     return;
                }
                
            
            currSprt.setSym((char)numOn);
            numOn++;
            Sprite[] temp = SprtData;
            SprtData = new Sprite[temp.length+1];
           for(int i=0;i<temp.length;i++)
            {
                SprtData[i] = temp[i];
            }
            SprtData[temp.length] = currSprt;
            jList5.setListData(SprtData);
            if(jRadioButton2.isSelected())
                jList1.setListData(SprtData);
        }
    }//GEN-LAST:event_jButton30ActionPerformed

    private void jRadioButton2MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton2MouseReleased
        // TODO add your handling code here:
        if(jRadioButton2.isSelected()){
            jList1.setListData(SprtData);
           // jCheckBox1.setEnabled(jRadioButton1.isSelected());
        }
    }//GEN-LAST:event_jRadioButton2MouseReleased

    private void jRadioButton1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton1MouseReleased
        // TODO add your handling code here:
        if(jRadioButton1.isSelected()){
            //jCheckBox1.setEnabled(jRadioButton1.isSelected());
            jList1.setListData(bkData);
        }
        
    }//GEN-LAST:event_jRadioButton1MouseReleased

    private void jButton39ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton39ActionPerformed
        // TODO add your handling code here:
        
        //ADD NPCS
        PeopleForm dialog = new PeopleForm(this,true);
        dialog.setVisible(true);
        People currPpl = dialog.getPPL();
        if(currPpl!=null)
        {
            for(int i=0;i<PplData.length;i++)
                if(PplData[i].getName().equals(currPpl.getName()))
                {
                     JOptionPane.showMessageDialog(null, "Name already exisits");
                     return;
                }
                
            
            currPpl.setSym((char)numOn);
            currPpl.setType("NPC");
            numOn++;
            People[] temp = PplData;
            PplData = new People[temp.length+1];
           for(int i=0;i<temp.length;i++)
            {
                PplData[i] = temp[i];
            }
            PplData[temp.length] = currPpl;
            jList9.setListData(PplData);
            if(jRadioButton3.isSelected())
                jList1.setListData(PplData);
        }
        
    }//GEN-LAST:event_jButton39ActionPerformed
  //block of code to save maps in a .cxm file
    
  
    
    
    
    private void jRadioButton3MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButton3MouseReleased
        // TODO add your handling code here:
        if(jRadioButton3.isSelected()){
           // jCheckBox1.setEnabled(jRadioButton1.isSelected());
            jList1.setListData(PplData);
        }
    }//GEN-LAST:event_jRadioButton3MouseReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseReleased
        // TODO add your handling code here:
        //SaveWriter();
        //Save();
        SaveForm form = new SaveForm(this,true);
        form.setVisible(true);   
        
        if(form.isVisible() == false){
           try{
            input = new BufferedReader(new FileReader(form.getFile()));
           }
           catch(FileNotFoundException e){}
           if(form.getSave()){
                jLabel7.setText("Saving Map...");
           try{
            if(!input.readLine().equals("")|| input.readLine() != null){
                tempFile = form.getFile();
                SaveWriter();
                Save();
            }
        }
        catch(IOException e){}
          }
        
        }
            

    
    }//GEN-LAST:event_jButton1MouseReleased
  
    public void SaveWriter(){
        try{
        input = new BufferedReader(new FileReader(tempFile));
        }
        catch(FileNotFoundException e){
            jLabel7.setText("Error saving map.");
        }
        
        try{
            String name = input.readLine();
            String dir = input.readLine();
           // File f = new File("cenexMapCreator\\temp.tmp");
           // f.delete();
            if(dir != null)
                output = new BufferedWriter(new FileWriter(new File(dir + "\\" + name + ".cxm")));
            else
                output = new BufferedWriter(new FileWriter(new File("maps\\" + name + ".cxm")));
            this.setTitle(name + ".cxm - Cenex Map Creator Alpha");
        }
        catch(IOException ex){
            jLabel7.setText("Could not save map." + ex);
        }
        //Save();
    }
    
    private void FilePrintLn(String name, String file, boolean walkon){
        try {
           // output.write(row + "\r\n" + col + "\r\n" + type + "\r\n" + name + "\r\n" + file + "\r\n" + walkon + "\r\n");
            output.write(file + "\r\n" + name + "\r\n" + walkon + "\r\n");
        } catch (IOException ex) {
            jLabel7.setText("Could not save map" + ex);
        }
    }
    private void FilePrintLn(String name, String file){
        try {
           // output.write(row + "\r\n" + col + "\r\n" + type + "\r\n" + name + "\r\n" + file + "\r\n" + "\r\n");
            output.write(file + "\r\n" + name + "\r\n");
        } catch (IOException ex) {
            jLabel7.setText("Could not save map."+ ex);
        }
    }

    
    public void Save(){
        try {
            output.write(bkImage[0].length + "\r\n" + bkImage.length + "\r\n");
            for (int r = 0; r < bkImage[0].length; r++) {
                for (int c = 0; c < bkImage.length; c++) {
                    FilePrintLn( bkImage[r][c].getName(), bkImage[r][c].getImage().getDescription(), bkImage[r][c].getWalkOn());
                    jLabel7.setText("Background saved.");
                    FilePrintLn(SprtImage[r][c].getName(), SprtImage[r][c].getImage().getDescription());
                    jLabel7.setText("Sprites saved.");
                    FilePrintLn(PplImage[r][c].getName(), PplImage[r][c].getImage().getDescription());
                    jLabel7.setText("People saved.");
                }
            }
            output.write(bkData.length + "\r\n");
            for(int i = 0; i < bkData.length; i++){
                FilePrintLn(bkData[i].getName(), bkData[i].getImage().getDescription(), bkData[i].getWalkOn());
            }
            output.write(SprtData.length + "\r\n");
            for(int i = 0; i < SprtData.length; i++){
                FilePrintLn(SprtData[i].getName(), SprtData[i].getImage().getDescription());
            }
            output.write(PplData.length + "\r\n");
            for(int i = 0; i < PplData.length; i++){
                FilePrintLn(PplData[i].getName(), PplData[i].getImage().getDescription());
                output.write(PplData[i].getType() + "\r\n");
            }
                    
            output.close();
            tempFile.deleteOnExit();
            jLabel7.setText("Finished Saving Map.");
        } catch (IOException ex) {
            jLabel7.setText("Could not save map." + ex);
        }
        ActionListener clearLabel = new ActionListener(){
        public void actionPerformed(ActionEvent e) {
            jLabel7.setText("");
        }
    };
    Timer t = new Timer(5000, clearLabel);
    t.start();
    t.setRepeats(false);
    if(jLabel7.getText().equals("")){
        t.restart();
        t.stop();
    }
    }
    
    private void jList1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseReleased
    
       /* if(bkImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()].getWalkOn())
            jCheckBox1.setSelected(true);
        else
            jCheckBox1.setSelected(false);*/
    }//GEN-LAST:event_jList1MouseReleased

    @SuppressWarnings("static-access")
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        //LOADS A NEW MAP
        int bkLen;
        int sprtLen;
        int pplLen;
        background[] bg;
        Sprite[] sp;
        People[] ppl;
        JFileChooser fc = new JFileChooser("C:\\Users\\chris\\Desktop\\cenexMapCreator\\maps");
        fc.setFileFilter(new CxmFileFilter());
        int returnVal = fc.showOpenDialog(this);
        if(returnVal == fc.APPROVE_OPTION)
            try{
                input = new BufferedReader(new FileReader(fc.getSelectedFile().getAbsolutePath()));
            }
            catch(FileNotFoundException e){}
        try{
            int row = Integer.valueOf(input.readLine());
            int col = Integer.valueOf(input.readLine());
            mainWin win = new mainWin(row,col);
            for(int r = 0; r < row; r++){
                for(int c = 0; c < col; c++){
                   // background b= new background(new ImageIcon(input.readLine()), input.readLine(), input.readLine().equals("true"));
                   win.paintTile(r,c, new background(new ImageIcon(input.readLine()), input.readLine(), input.readLine().equals("true")),
                           new Sprite(new ImageIcon(input.readLine()), input.readLine()),
                           new People(new ImageIcon(input.readLine()), input.readLine())); 
                }
            }

            bkLen = Integer.valueOf(input.readLine());
            bg = new background[bkLen];
            for(int i = 0; i < bkLen; i++){
                    bg[i] =  new background(new ImageIcon(input.readLine()),
                            input.readLine(), input.readLine().equals("true"));
            }
            win.setBkData(bg);            
            sprtLen = Integer.valueOf(input.readLine());
            sp = new Sprite[sprtLen];
            for(int i = 0; i < sprtLen; i++){
                sp[i] = new Sprite(new ImageIcon(input.readLine()),
                        input.readLine());
            }
            win.setSprtData(sp);
            pplLen = Integer.valueOf(input.readLine());
            ppl = new People[pplLen];
            for(int i = 0; i < pplLen; i++){
                ppl[i] = new People(new ImageIcon(input.readLine()),
                        input.readLine());
                ppl[i].setType(input.readLine());
            }
            win.setPplData(ppl);
            win.setVisible(true);
            this.setVisible(false);

                    
           
        }
        catch(IOException e){}
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        if(jTable1.getSelectedRow() > -1 || jTable1.getSelectedColumn() > -1){
            TileView dialogue = new TileView(this,true, jTable1.getSelectedRow(), jTable1.getSelectedColumn(), 
                    bkImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()], 
                    SprtImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()],
                    PplImage[jTable1.getSelectedRow()][jTable1.getSelectedColumn()]);
            dialogue.setVisible(true);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton28MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton28MouseReleased
        // TODO add your handling code here:
        // SPRITE EDIT
        
       SpriteForm dialog = new SpriteForm(this,true,((Sprite)jList5.getSelectedValue()));
       dialog.setVisible(true);
       Sprite currSprt = dialog.getEditedSPRT();
       if(currSprt!=null)
       {
       for(int i=0;i<SprtData.length;i++)
           //DOES NOT WORK WITH EDIT
      /* if(SprtData[i].getName().equals(currSprt.getName()))
       {
          JOptionPane.showMessageDialog(null, "Name already exisits");
          return;
       }*/
            SprtData[jList5.getSelectedIndex()] = currSprt;
            
            jList5.setListData(SprtData);
            if(jRadioButton2.isSelected())
                jList1.setListData(SprtData);
        }
    }//GEN-LAST:event_jButton28MouseReleased

    private void jButton29ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton29ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton29ActionPerformed

    private void jButton29MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton29MouseReleased
        // TODO add your handling code here:
        // SPRITE REMOVE
      if(SprtData.length>0&&jList5.getSelectedIndex()!=0)
      {
        Sprite[] temp = SprtData;
        SprtData = new Sprite[temp.length-1];
          for(int i=jList5.getSelectedIndex();i<temp.length-1;i++)
                temp[i]=temp[i+1];
         for(int i=0;i<temp.length-1;i++)
         {
             SprtData[i] = temp[i];
         }
                   jList5.setListData(SprtData);
                  if(jRadioButton2.isSelected())
                    jList1.setListData(SprtData);
      }
    }//GEN-LAST:event_jButton29MouseReleased

    private void jButton4MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseReleased
        // TODO add your handling code here:
        //SET MAIN PLAYER INFO
        if(!jTextField1.getText().equals("")){
            People mainPlayer = new Player(new ImageIcon("Cenex_blink.gif"), jTextField1.getText(), Integer.valueOf(jTextField2.getText()),
                    Integer.valueOf(jTextField4.getText()), 0, 0, 0, 0);
            People[] temp = PplData;
            PplData = new People[temp.length + 1];
            for(int k = 0; k < temp.length; k++)
                PplData[k] = temp[k];
            PplData[temp.length] = mainPlayer;
            if(jRadioButton3.isSelected())
                jList1.setListData(PplData);
        }
            
            
        
    }//GEN-LAST:event_jButton4MouseReleased
    
  
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new mainWin(5,5).setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backAdd;
    private javax.swing.JButton backEdit;
    private javax.swing.JButton backRem;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton22;
    private javax.swing.JButton jButton23;
    private javax.swing.JButton jButton24;
    private javax.swing.JButton jButton28;
    private javax.swing.JButton jButton29;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton30;
    private javax.swing.JButton jButton31;
    private javax.swing.JButton jButton32;
    private javax.swing.JButton jButton33;
    private javax.swing.JButton jButton34;
    private javax.swing.JButton jButton35;
    private javax.swing.JButton jButton36;
    private javax.swing.JButton jButton37;
    private javax.swing.JButton jButton38;
    private javax.swing.JButton jButton39;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JList jList1;
    private javax.swing.JList jList4;
    private javax.swing.JList jList5;
    private javax.swing.JList jList6;
    private javax.swing.JList jList7;
    private javax.swing.JList jList8;
    private javax.swing.JList jList9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
    
}
